package com.it00zyq.admin.controller;

import com.it00zyq.admin.param.LoginParam;
import com.it00zyq.admin.param.RegisterParam;
import com.it00zyq.admin.service.UserService;
import com.it00zyq.common.utils.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author zyq
 * @Date 2022/4/25 16:19
 * @Description TODO
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;
    /**
     * 登录
     * @return 返回用户信息和令牌token
     */
    @PostMapping("/login")
    public R login(@RequestBody @Valid LoginParam param) {
        return R.ok().data(userService.login(param));
    }


    /**
     * 登录
     * @return 返回用户信息和令牌token
     */
    @PostMapping("/register")
    public R login(@RequestBody @Valid RegisterParam param) {
        userService.register(param);
        return R.ok();
    }


}
